<?php
function login($db) {
    if (!isset($_REQUEST['username']) || !isset($_REQUEST['password'])) {
        return array('sessionId' => '0');
    }
    $check = new UserRepository();
    if ($check->checkUser($db, $_REQUEST['username'], $_REQUEST['password'])) {
        session_start();
        $_SESSION['username'] = $_REQUEST['username'];
        return array('sessionId' => session_id());
    }
    return array('sessionId' => '0');
}
?>
